package cn.itcast.listener;

import cn.itcast.domain.system.User;
import cn.itcast.utils.MailUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import java.io.IOException;

public class EmailListener2 implements MessageListener {
    private ObjectMapper objectMapper = new ObjectMapper();
    @Override
    public void onMessage(Message message) {
        //拿到用户的信息
        byte[] body = message.getBody();
        //把json字符串转换成User对象
        try {
            User user = objectMapper.readValue(body, User.class);
            MailUtil.sendMsg(user.getEmail(),"交货期限提前3天自动邮件提醒","起来!!!给创智打钱");
            System.out.println("发送3天过期自动提醒-邮箱成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
